﻿using System;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Catel.Data;

namespace Catel.Articles._03___MVVM.Models
{
    /// <summary>
    /// Table Data object class which fully supports serialization, property changed notifications,
    /// backwards compatibility and error checking.
    /// </summary>
    [Serializable]
    public class Table : DataObjectBase<Table>
    {
        #region Variables
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes a new object from scratch.
        /// </summary>
        public Table()
            : this(NameProperty.GetDefaultValue<string>()) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="Table"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public Table(string name)
        {
            // Create collections
            Chairs = new ObservableCollection<Chair>();

            // Store values
            Name = name;
        }

        /// <summary>
        /// Initializes a new object based on <see cref="SerializationInfo"/>.
        /// </summary>
        /// <param name="info"><see cref="SerializationInfo"/> that contains the information.</param>
        /// <param name="context"><see cref="StreamingContext"/>.</param>
        protected Table(SerializationInfo info, StreamingContext context)
            : base(info, context) { }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        public string Name
        {
            get { return GetValue<string>(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        /// <summary>
        /// Register the Name property so it is known in the class.
        /// </summary>
        public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof(string), "Table");

        /// <summary>
        /// Gets or sets a collection of chairs.
        /// </summary>
        public ObservableCollection<Chair> Chairs
        {
            get { return GetValue<ObservableCollection<Chair>>(ChairsProperty); }
            set { SetValue(ChairsProperty, value); }
        }

        /// <summary>
        /// Register the Chairs property so it is known in the class.
        /// </summary>
        public static readonly PropertyData ChairsProperty = RegisterProperty("Chairs", typeof(ObservableCollection<Chair>));
        #endregion

        #region Methods
        #endregion
    }
}
